﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Corte.ascx.cs" Inherits="CustomControls_Procesos" %>
<div class="form">
    <fieldset><legend>&nbsp;Detalles del Corte&nbsp;</legend>
        <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="lblModel" AssociatedControlID="drpModel" Text="<span class='required-mark'>*</span> Modelo"></asp:Label>
            <asp:DropDownList runat="server" ID="drpModel" CssClass="field"></asp:DropDownList>
            <asp:RequiredFieldValidator ID="FNvalidator" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="drpModel" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
        </div>
        <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="lblGender" AssociatedControlID="drpGender" Text="<span class='required-mark'>*</span> G&eacute;nero"></asp:Label>
            <asp:DropDownList runat="server" ID="drpGender" CssClass="field">
                <asp:ListItem Text="Seleccione..." Value=""></asp:ListItem>
                <asp:ListItem Text="Ni&ntilde;o" Value="nino"></asp:ListItem>
                <asp:ListItem Text="Ni&ntilde;a" Value="nina"></asp:ListItem>
                <asp:ListItem Text="Mujer" Value="mujer"></asp:ListItem>
                <asp:ListItem Text="Hombre" Value="hombre"></asp:ListItem>
            </asp:DropDownList>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="drpGender" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
        </div>
        <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="Label1" AssociatedControlID="txtDate" Text="<span class='required-mark'>*</span> Fecha"></asp:Label>
            <asp:TextBox runat="server" ID="txtDate" CssClass="short-field" MaxLength="10"></asp:TextBox> dd/mm/aaaa
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="txtDate" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
        </div>
        <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="lblSizes" AssociatedControlID="rptSizes" Text="<span class='required-mark'>*</span> Tallas"></asp:Label>
            <div class="items-container">
                <asp:Repeater ID="rptSizes" runat="server">
                    <ItemTemplate>
                        <div class="item-sizes">
                            <asp:HiddenField runat="server" ID="hdnSizeId" Value='<%# Bind("SizeId") %>' />
                            <asp:CheckBox runat="server" CssClass="chk-sizes" Checked='<%# isChecked(Eval("Quantity")) %>' ID='chkSizes'  Text='<%# Bind("Name") %>' />
                            <asp:TextBox runat="server" CssClass="qyt-sizes" ID="txtQuantity" MaxLength="10" Width="30px" Text='<%# Bind("Quantity") %>' />
                        </div>
                    </ItemTemplate>
                </asp:Repeater> 
                <div class="clear"></div> 
                <asp:Label runat="server" ID="lblErrorSizes" ForeColor="Red"></asp:Label>
            </div>
            <div class="clear"></div>           
        </div>
        <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="lblFabric" AssociatedControlID="drpFabric" Text="<span class='required-mark'>*</span> Tela"></asp:Label>
            <asp:DropDownList runat="server" ID="drpFabric" CssClass="field"></asp:DropDownList>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="drpFabric" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
        </div>
        <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="lblWidth" AssociatedControlID="txtWidth" Text="<span class='required-mark'>*</span> Ancho"></asp:Label>
            <asp:TextBox runat="server" ID="txtWidth" CssClass="short-field"></asp:TextBox> Mts.
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="txtWidth" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
            <asp:CompareValidator runat="server" ID="valWidth" ControlToValidate="txtWidth" Type="Double" ForeColor="Red" Display="Dynamic" SetFocusOnError="true" ErrorMessage="Valor Inv&aacute;lido"></asp:CompareValidator>
        </div>
        <div class="field-line">
            <label class="left">Cantidad de pantalones</label>
            <span id="txtNumberOfPants" runat="server">10</span> pantalones
            <div class="clear"></div>
        </div>
        
        <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="lblQytProduction" AssociatedControlID="txtQytProduction" Text="<span class='required-mark'>*</span> Cantidad para el corte"></asp:Label>
            <asp:TextBox runat="server" ID="txtQytProduction" CssClass="short-field"></asp:TextBox> Mts.
            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="txtQytProduction" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
            <asp:CompareValidator runat="server" ID="CompareValidator1" ControlToValidate="txtQytProduction" Type="Double" ForeColor="Red" Display="Dynamic" SetFocusOnError="true" ErrorMessage="Valor Inv&aacute;lido"></asp:CompareValidator>
            <div class="clear"></div>
        </div>
        
        <div class="field-line">
            <label class="left">Cantidad promedio por prenda</label>
            <span id="txtAverage" runat="server">20</span> Mts.
            <div class="clear"></div>
        </div>
        <div class="field-line">
            <asp:Label runat="server" CssClass="left" ID="lblProcess" AssociatedControlID="drpProcess" Text="<span class='required-mark'>*</span> Procesos"></asp:Label>
            <asp:DropDownList runat="server" ID="drpProcess" CssClass="field"></asp:DropDownList>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="drpProcess" ErrorMessage="Requerido"></asp:RequiredFieldValidator>
        </div>
        <div class="buttons-actions">
            <asp:Button runat="server" ID="btnSave" OnClick="btnSave_Click" Text="Guardar" />
            <asp:Button runat="server" ID="btnCancel" OnClick="btnCancel_Click" CausesValidation="false" Text="Cancelar" />
        </div>
    </fieldset>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#<%= txtDate.ClientID%>").datepicker({
                dateFormat: 'dd/mm/yy'
            });
            $(".chk-sizes input").click(function(){
                getValues()
            });
            $(".qyt-sizes").change(function () {
                getValues()
            });
            $("#<%= txtQytProduction.ClientID%>").change(function () {
                getValues()
            });
        })
        function getValues()
        {
            var total = 0;
            $(".chk-sizes input").each(function () {

                if ($(this).attr('checked') == 'checked')
                {
                    value = parseInt($(this).parent().parent().find(".qyt-sizes").val(), 10);
                    if(!isNaN(value))
                        total += value;
                }
            });
            $("#<%= txtNumberOfPants.ClientID%>").html(total);
            if ($("#<%= txtQytProduction.ClientID%>").val() != '')
            {
                qyt = parseInt($("#<%= txtQytProduction.ClientID%>").val(), 10);

                if(!isNaN(qyt) && total > 0)
                    $("#<%= txtAverage.ClientID%>").html(Math.round((qyt / total) * 100) / 100);
                else
                    $("#<%= txtAverage.ClientID%>").html(0);

            }
        }
    </script>
</div>    